home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
STUTTGART
/
UTIL
/
SCREEN
/
DIGI
/
!DigiClock
/
c
/
dclock
next >
Wrap
Text File
|
1994-04-29
|
8KB
|
340 lines
/* This module provides the entire digital
* clock functionality.
*/
#include <time.h>
#include "wimp.h"
#include "dclock.h"
#include "win.h"
#include "event.h"
#include "wimp.h"
#include "template.h"
#include "h.bbc"
#include "h.sprite"
#include "h.resspr"
#include <stdlib.h>
#include <string.h>
void dclock_gettime(dclock_str *dclock)
{
struct tm *mytime;
time_t t;
time(&t);
mytime=localtime(&t);
dclock->initial_time=*mytime;
dclock->et=360000*mytime->tm_hour+6000*mytime->tm_min+100*mytime->tm_sec;
}
void sprite_name(char *str, int dig)
{
strcpy(str,"dig_");
str[4]=dig+'0';
str[5]='\0';
}
void dclock_display(wimp_redrawstr *redraw, dclock_str *dclock)
{
sprite_area *myarea=resspr_area();
sprite_pixtrans t[48];
sprite_factors f;
sprite_id id;
char name[13];
int xmin,xmax;
int et;
et=dclock->et;
id.tag=0;
id.s.name=name;
xmin=redraw->g.x0-redraw->box.x0;
xmax=redraw->g.x1-redraw->box.x0;
if (xmin<116) {
sprite_name(name,((et%8640000)/3600000)%3);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0,redraw->box.y0+dclock->old.hour1,&f,t);
if (dclock->old.hour1!=0) {
sprite_name(name,((((et+3600000)%8640000)/3600000))%3);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0,redraw->box.y0+dclock->old.hour1-136,&f,t);
}
}
if (xmin<(116*2) && xmax>=116) {
sprite_name(name,((et/360000)%24)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116,redraw->box.y0+dclock->old.hour0,&f,t);
if (dclock->old.hour0!=0) {
sprite_name(name,(((et/360000)+1)%24)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116,redraw->box.y0+dclock->old.hour0-136,&f,t);
}
}
if (xmin<(116*3) && xmax>=(116*2)) {
strcpy(name,"colon");
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*2,redraw->box.y0,&f,t);
}
if (xmin<(116*4) && xmax>=(116*3)) {
sprite_name(name,(et/60000)%6);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*3,redraw->box.y0+dclock->old.min1,&f,t);
if (dclock->old.min1!=0) {
sprite_name(name,((et/60000)+1)%6);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*3,redraw->box.y0+dclock->old.min1-136,&f,t);
}
}
if (xmin<(116*5) && xmax>=(116*4)) {
sprite_name(name,(et/6000)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*4,redraw->box.y0+dclock->old.min0,&f,t);
if (dclock->old.min0!=0) {
sprite_name(name,(et/6000+1)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*4,redraw->box.y0+dclock->old.min0-136,&f,t);
}
}
if (xmin<(116*6) && xmax>=(116*5)) {
strcpy(name,"dot");
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*5,redraw->box.y0,&f,t);
}
if (xmin<(116*7) && xmax>=(116*6)) {
sprite_name(name,(et/1000)%6);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*6,redraw->box.y0+dclock->old.sec1,&f,t);
if (dclock->old.sec1!=0) {
sprite_name(name,(et/1000+1)%6);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*6,redraw->box.y0+dclock->old.sec1-136,&f,t);
}
}
if (xmin<(116*8) && xmax>=(116*7)) {
sprite_name(name,(et/100)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*7,redraw->box.y0+dclock->old.sec0,&f,t);
if (dclock->old.sec0!=0) {
sprite_name(name,(et/100+1)%10);
wimp_readpixtrans(myarea,&id,&f,t);
sprite_put_scaled(myarea,&id,0,redraw->box.x0+116*7,redraw->box.y0+dclock->old.sec0-136,&f,t);
}
}
}
void dclock_handle_redraw(wimp_eventstr *event, dclock_str *dclock)
{
int flag=FALSE;
wimp_redrawstr redraw;
redraw.w=event->data.o.w;
wimp_redraw_wind(&redraw,&flag);
while(flag) {
dclock_display(&redraw,dclock);
wimp_get_rectangle(&redraw,&flag);
}
}
void dclock_destroy(dclock_str *dclock)
{
wimp_delete_wind(dclock->handle);
win_activedec();
}
void dclock_update(dclock_str *dclock, int no)
{
wimp_redrawstr r;
int flag;
r.box.x0=no*116;
r.box.x1=no*116+116;
r.box.y0=-136;
r.box.y1=0;
r.w=dclock->handle;
wimp_update_wind(&r,&flag);
while(flag) {
dclock_display(&r,dclock);
wimp_get_rectangle(&r,&flag);
}
}
void dclock_handle_idle(dclock_str *dclock)
{
int et,ct,dt;
time_t t;
struct tm *hms;
et=dclock->et;
time(&t);
hms=localtime(&t);
ct=360000*hms->tm_hour+6000*hms->tm_min+100*hms->tm_sec+(et%100);
dt=ct-et+400;
if (dt<=-4320000)
dt+=8640000;
else if (dt>=4320000)
dt-=8640000;
if (dt>8000)
dt=8000;
else if (dt<-8000)
dt=-8000;
et=(et*100+dt)/100;
et=(et+8640000)%8640000;
dclock->et=et;
if ((et%100)>50)
{
dclock->new.sec0=((et%100-50)*30)/11;
}
else
{
dclock->new.sec0=0;
}
if ((et%1000)>950)
dclock->new.sec1=((et%1000-950)*30)/11;
else
dclock->new.sec1=0;
if ((et%6000)>5950)
dclock->new.min0=((et%6000-5950)*30)/11;
else
dclock->new.min0=0;
if ((et%60000)>59950)
dclock->new.min1=((et%60000-59950)*30)/11;
else
dclock->new.min1=0;
if ((et%360000)>359950)
dclock->new.hour0=((et%360000-359950)*30)/11;
else
dclock->new.hour0=0;
if ((et%8640000)>8639950)
dclock->new.hour1=((et%8640000-863950)*30)/11;
else
dclock->new.hour1=0;
if ((et%3600000)>3599950)
dclock->new.hour1=((et%3600000-3599950)*30)/11;
else
dclock->new.hour1=0;
if (dclock->new.sec0!=dclock->old.sec0 || dclock->val.sec0!=(et/100)) {
dclock->old.sec0=dclock->new.sec0;
dclock->val.sec0=et/100;
dclock_update(dclock,7);
}
else
return;
if (dclock->new.sec1!=dclock->old.sec1 || dclock->val.sec1!=(et/1000)) {
dclock->old.sec1=dclock->new.sec1;
dclock->val.sec0=et/1000;
dclock_update(dclock,6);
}
else
return;
if (dclock->new.min0!=dclock->old.min0 || dclock->val.min0!=(et/6000)) {
dclock->old.min0=dclock->new.min0;
dclock->val.min0=et/6000;
dclock_update(dclock,4);
}
else
return;
if (dclock->new.min1!=dclock->old.min1 || dclock->val.min1!=(et/60000)) {
dclock->old.min1=dclock->new.min1;
dclock->val.min1=et/60000;
dclock_update(dclock,3);
}
else
return;
if (dclock->new.hour0!=dclock->old.hour0 || dclock->val.hour0!=(et/360000)) {
dclock->old.hour0=dclock->new.hour0;
dclock->val.hour0=et/360000;
dclock_update(dclock,1);
}
else
return;
if (dclock->new.hour1!=dclock->old.hour1 || dclock->val.hour1!=(et/3600000)) {
dclock->old.hour1=dclock->new.hour1;
dclock->val.hour1=et/3600000;
dclock_update(dclock,0);
}
}
void dclock_event_handler(wimp_eventstr *event, void *handle)
{
dclock_str *dclock=(dclock_str *) handle;
switch(event->e) {
case wimp_ENULL:
dclock_handle_idle(dclock);
break;
case wimp_ECLOSE:
dclock_destroy(dclock);
break;
case wimp_EOPEN:
wimp_open_wind(&(event->data.o));
break;
case wimp_EREDRAW:
dclock_handle_redraw(event,dclock);
break;
}
}
void dclock_create(dclock_str *dclock)
{
wimp_wstate state;
template *temp;
temp=template_copy(template_find("clock"));
wimp_create_wind(&(temp->window),&(dclock->handle));
wimp_get_wind_state(dclock->handle,&state);
state.o.behind=-1;
wimp_open_wind(&state.o);
win_register_event_handler(dclock->handle,&dclock_event_handler,(void *)dclock);
win_activeinc();
win_claim_idle_events(dclock->handle);
event_setmask(0);
dclock_gettime(dclock);
dclock_handle_idle(dclock);
}